package com.zx._10_设计模式.行为型模式.策略模式;

import java.util.HashMap;

public class Strategy {

    // 初始化策略
    private static HashMap<Integer, MemberRule> map = new HashMap<>();

    // 注册多种策略【被动注册策略】
    static {
        map.put(MemberRule.A, new RuleA());
        map.put(MemberRule.B, new RuleB());
        map.put(MemberRule.C, new RuleC());
    }

    public static double price(int ruleType, double price) {
        MemberRule rule = map.get(ruleType);
        if (rule == null) {
            throw new RuntimeException("没有这种会员");
        }
        return rule.memberPrice(price);
    }


    public static void main(String[] args) {
        System.out.println(Strategy.price(MemberRule.A, 10));
        System.out.println(Strategy.price(MemberRule.B, 10));
        System.out.println(Strategy.price(MemberRule.C, 10));
        System.out.println(Strategy.price(0, 10));
    }
}
